Render(RectangleF,Single,EventHandler<ProgressEventArgs>,EventHandler<IntermediateImageRequestEventArgs>) Метод (PdfPage)
Отрисовывает указанный прямоугольник PDF страницы с указанным масштабом.
Parameters
- rect
- Прямоугольник исходного изображения.
- scale
- Масштабный коэффициент.
- renderingProgress
- Делегат хода выполнения визуализации изображения.
- intermediateImageRequest
- Делегат для запроса промежуточного изображения. Может быть установлен в null (Nothing в Visual Basic)
Return Value
Отрисованное изображение этой страницы.
Вот пример, показывающий, как отрисовывать PDF страницу постепенно:
''' <summary>
''' The timer for getting intermediate images.
''' </summary>
Public _timer As New System.Diagnostics.Stopwatch()
''' <summary>
''' The index of intermediate image.
''' </summary>
Public _intermediateImageIndex As Integer = 0
''' <summary>
''' Time interval, in milliseconds, for getting intermediate image during rendering.
''' </summary>
Public INTERMEDIATE_RENDER_IMAGE_INTERVAL As Integer = 300
''' <summary>
''' Gets the image of PDF page.
''' </summary>
''' <param name="page">The page of PDF document.</param>
Public Function RenderPdfPageProgressively(page As Vintasoft.Imaging.Pdf.Tree.PdfPage) As Vintasoft.Imaging.VintasoftImage
_intermediateImageIndex = 0
' start timer
_timer.Start()
' render PDF page progressively
Dim image As Vintasoft.Imaging.VintasoftImage = page.Render(page.CropBox, 1F, Nothing, New System.EventHandler(Of Vintasoft.Imaging.ImageRendering.IntermediateImageRequestEventArgs)(AddressOf IntermediateImageRequest))
' stop timer
_timer.[Stop]()
' return the result image
Return image
End Function
''' <summary>
''' Handler of event that occurs when intermediate image is ready and can be obtained.
''' </summary>
Public Sub IntermediateImageRequest(sender As Object, e As Vintasoft.Imaging.ImageRendering.IntermediateImageRequestEventArgs)
' if intermediate image must be saved
If _timer.ElapsedMilliseconds >= INTERMEDIATE_RENDER_IMAGE_INTERVAL Then
' reset timer
_timer.Reset()
' set the delegate which invoked for obtaining the intermediate image
e.IntermediateImageCompleted = New Vintasoft.Imaging.ImageRendering.IntermediateImageCompletedDelegate(AddressOf IntermediateImageReady)
' start timer
_timer.Start()
End If
End Sub
''' <summary>
''' Delegate that allows to obtain intermediate image.
''' </summary>
Public Sub IntermediateImageReady(e As Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs)
' increment counter of intermediate images
_intermediateImageIndex += 1
' clone the rendered image
Using image As Vintasoft.Imaging.VintasoftImage = DirectCast(e.Image.Clone(), Vintasoft.Imaging.VintasoftImage)
Dim filename As String = String.Format("IntermediateImage_{0}.bmp", _intermediateImageIndex.ToString("00"))
' save the intermediate image to a file
image.Save(filename)
End Using
End Sub
/// <summary>
/// The timer for getting intermediate images.
/// </summary>
public System.Diagnostics.Stopwatch _timer = new System.Diagnostics.Stopwatch();
/// <summary>
/// The index of intermediate image.
/// </summary>
public int _intermediateImageIndex = 0;
/// <summary>
/// Time interval, in milliseconds, for getting intermediate image during rendering.
/// </summary>
public int INTERMEDIATE_RENDER_IMAGE_INTERVAL = 300;
/// <summary>
/// Gets the image of PDF page.
/// </summary>
/// <param name="page">The page of PDF document.</param>
public Vintasoft.Imaging.VintasoftImage RenderPdfPageProgressively(
Vintasoft.Imaging.Pdf.Tree.PdfPage page)
{
_intermediateImageIndex = 0;
// start timer
_timer.Start();
// render PDF page progressively
Vintasoft.Imaging.VintasoftImage image = page.Render(page.CropBox, 1.0f, null,
new System.EventHandler<Vintasoft.Imaging.ImageRendering.IntermediateImageRequestEventArgs>(IntermediateImageRequest));
// stop timer
_timer.Stop();
// return the result image
return image;
}
/// <summary>
/// Handler of event that occurs when intermediate image is ready and can be obtained.
/// </summary>
public void IntermediateImageRequest(object sender, Vintasoft.Imaging.ImageRendering.IntermediateImageRequestEventArgs e)
{
// if intermediate image must be saved
if (_timer.ElapsedMilliseconds >= INTERMEDIATE_RENDER_IMAGE_INTERVAL)
{
// reset timer
_timer.Reset();
// set the delegate which invoked for obtaining the intermediate image
e.IntermediateImageCompleted =
new Vintasoft.Imaging.ImageRendering.IntermediateImageCompletedDelegate(IntermediateImageReady);
// start timer
_timer.Start();
}
}
/// <summary>
/// Delegate that allows to obtain intermediate image.
/// </summary>
public void IntermediateImageReady(Vintasoft.Imaging.ImageRendering.IntermediateImageReadyEventArgs e)
{
// increment counter of intermediate images
_intermediateImageIndex++;
// clone the rendered image
using (Vintasoft.Imaging.VintasoftImage image =
(Vintasoft.Imaging.VintasoftImage)e.Image.Clone())
{
string filename = string.Format("IntermediateImage_{0}.bmp", _intermediateImageIndex.ToString("00"));
// save the intermediate image to a file
image.Save(filename);
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5